package com.wangbo.box.factory;


public class FactoryPattern {


    public static void main(String[] args) {
        Factory factory = new SubjectAFactory();
        Subject subject = factory.create();
        subject.show();
    }

    static abstract class Subject{
        abstract void show();
    }

    static class SubjectA extends Subject{

        @Override
        void show() {
            System.out.println("SubjectA");
        }
    }

    static class SubjectB extends Subject{

        @Override
        void show() {
            System.out.println("SubjectB");
        }
    }

    interface Factory{

        Subject create();
    }

    static class SubjectAFactory implements Factory{

        @Override
        public Subject create() {
            return new SubjectA();
        }
    }

    static class SubjectBFactory implements Factory{

        @Override
        public Subject create() {
            return new SubjectB();
        }
    }

}
